<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/erp/js/html5.js"></script>
    <script type="text/javascript" src="/erp/js/respond.min.js"></script>
    <script type="text/javascript" src="/erp/js/PIE_IE678.js"></script>
    <![endif]-->
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link href="/erp/assets/css/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link href="/erp/assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/erp/css/style.css"/>
    <link rel="stylesheet" href="/erp/assets/css/ace.min.css"/>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome.min.css"/>
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <script src="/erp/js/jquery-1.9.1.min.js"></script>
    <script src="/erp/assets/js/bootstrap.min.js"></script>
    <!--[if IE 7]>
    <link rel="stylesheet" href="/erp/assets/css/font-awesome-ie7.min.css"/>
    <![endif]-->
    <link href="/erp/Widget/icheck/icheck.css" rel="stylesheet" type="text/css"/>
    <link href="/erp/Widget/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css"/>
    <title>分类管理</title>
</head>
<body>
<div class="clearfix" id="add_picture">
    <div class="type_style">
        <div class="type_title">一级分类</div>
        <div class="type_content">
        <span id="spans1" style="display:block">
        <form class="form form-horizontal" id="form-user-add">
			  <ul class=" page-content">
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类编号：</label>
			  <div class="formControls " style="width:280px;">
				 <input type="text" class="input-text" id="sort_id" placeholder="分类编号" name="id">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类名称：</label>
			  <div class="formControls ">
				<input type="text" class="input-text" id="sortName" placeholder="分类名称" name="sortName">
			  </div>
			</div>
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>添加人：</label>
			  <div class="formControls ">
				<input type="text" id="adder" class="input-text" placeholder="添加人" name="adder">
			  </div>
			</div>
			<input type="hidden" name="sortType" value="1">
			
			<div class="Operate_cont clearfix">
			  <label class="form-label"><span class="c-red">*</span>分类介绍：</label>
			  <div class="formControls">
				<textarea id="sortRecommend" name="sortRecommend" class="textarea" placeholder="说点什么...最少输入10个字符"
                          dragonfly="true" nullmsg="备注不能为空！"></textarea>

			  </div>
			</div>
		  </ul>
		<div class="">
            <div class="" style=" text-align:center">
              <input id="btn" class="btn btn-primary radius" type="button" value="保存并应用">
			  <input class="btn btn-primary radius" type="reset" value="重置">
            </div>
          </div></form>
		</span>
        </div>
    </div>
</div>
<script type="text/javascript">
    $("#btn").on("click", function () {
        var sort_id = $("#sort_id").val();
        var re = /^[a-zA-Z0-9]+$/;
        if (!re.test(sort_id)) {
            layer.tips('请输入数字或者字母!', '#sort_id', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sort_id").focus();
        } else if ($("#sort_id").val().length == 0) {
            layer.tips('请输入编号!', '#sort_id', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sort_id").focus();
        } else if ($("#sortName").val().length == 0) {
            layer.tips('请输入名称!', '#sortName', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sortName").focus();
        } else if ($("#adder").val().length == 0) {
            layer.tips('请输入添加人!', '#adder', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#adder").focus();
        } else if ($("#sortRecommend").val().length == 0) {
            layer.tips('请输入介绍!', '#sortRecommend', {
                tips: [2, 'red'],
                time: 2000
            });
            $("#sortRecommend").focus();
        } else {
            $.ajax({
                url: '/sort/sortById',
                data: {
                    "id": $("#sort_id").val(),
                },
                contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                success: function (data) {
                    if (data.result == true) {
                        layer.tips('该分类已存在!', '#sort_id', {
                            tips: [2, 'red'],
                            time: 2000
                        });
                        $("#sort_id").focus();
                    } else {
                        $.ajax({
                            url: '/sort/sortByName',
                            data: {
                                "sortName": $("#sortName").val(),
                            },
                            contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                            dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                            success: function (data) {
                                if (data.result == true) {
                                    layer.tips('该分类已存在!', '#sortName', {
                                        tips: [2, 'red'],
                                        time: 2000
                                    });
                                    $("#sortName").focus();
                                } else {
                                    $.ajax({
                                        url: '/sort/addsort',
                                        data: {
                                            "id": $("#sort_id").val(),
                                            "sortName": $("#sortName").val(),
                                            "adder": $("#adder").val(),
                                            "sortRecommend": $("#sortRecommend").val(),
                                        },
                                        contentType: 'application/json',           //表示我们发送给服务器数据是json格式
                                        dataType: 'json',                          //表示服务器返回给我们的数据是json格式
                                        success: function (data) {
                                            if (data.result == true) {
                                                layer.msg('添加成功！', {icon: 1, time: 1000}, function () {
                                                    window.location.href = "/sort/sortment";
                                                });
                                            } else {
                                                layer.msg('添加失败！', {icon: 1, time: 1000}, function () {
                                                    window.location.href = "/sort/sortment";
                                                });
                                            }
                                        }
                                    })
                                }
                            }
                        })
                    }
                }
            })
        }
    })

</script>
</body>
</html>
